import Base from "@/common/base.js"
class Index extends Base{
	constructor() {
	    super();
	};
	//不需要验证的
	getPublicMember(data,url,act,callBack) {
		var that = this;
		var params = {
			url: url,  
			method: act,
			data: data,
			sCallBack: function(res) {
				callBack && callBack(res);
			}
		};
		that.requsetGet(params);
	};
	//需要验证的
	getPublicUserMember(data,url,act,callBack) {
		var that = this;
		var params = {
			url: url,  
			method: act,
			data: data,
			sCallBack: function(res) {
				callBack && callBack(res);
			}
		};
		that.requestUser(params);
	};
	
	getUserLogin(eqnumber) {
		//1、拉起授权
		uni.getUserProfile({
			provider:'weixinlogin',
			desc:"小程序授权登录",
			success: (wxlg) => {
				//2、获取code
				uni.login({
					provider:"wadaze",
					success: (res) => {
						let udata={
							"codestr":res.code,
							"avatarUrl":wxlg.userInfo.avatarUrl,
							"nickName":wxlg.userInfo.nickName,
							"eqcode":eqnumber
						}
						//3、调用登录接口
						this.getPublicMember(udata,'wxlogin','get',sxlg=>{
							let user=sxlg.data;
							console.log(user);
							if(user.code==200){
								uni.setStorageSync('userid',user.data.userid);
								uni.setStorageSync('userinfo',user.data.userInfo);
								uni.setStorageSync('phone',user.data.userInfo.phone);
							}else{
								this.show_tips(sxlg.data.msg);
								return false;
							}
						});
					}
				})
			}
		})
	}
	//获取手机号操作
	onGetPhoneNumber(e) {
		this.$refs.phones.close();
		let arr={
			'codestr':e.detail.code,
			'userid':uni.getStorageSync('userid')
		}
		this.getPublicMember(arr,'getPhones','get',res=>{
			if(res.data.code == 200){
				uni.setStorageSync('phone',res.data.data.phone);
				this.show_tips(res.data.msg);
			}else{
				this.show_tips(res.data.msg);
				return false;
			}
		})
	}
}
export default Index;